
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/storeEvaluate/provider/provider.dart';
import 'package:boss/ui/page/storeEvaluate/widget/item_header.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ItemBlock extends StatelessWidget {
  dynamic data;
  dynamic provider;
  int index;
  ValueChanged<dynamic> onConfirm;
  ItemBlock({Key key,this.data,this.provider,this.index,this.onConfirm}):super(key:key);


  List<dynamic> get commentFold{
    var newArr=[];
    if(data["commentReplyDOList"].length!=0){
      newArr.add(data["commentReplyDOList"][0]);
    }

    return newArr;
  }





  @override
  Widget build(BuildContext context) {
    return Container(
      key:Key(data["id"].toString() ?? DateTime.now().millisecondsSinceEpoch.toString()),
      child: Column(
        children: <Widget>[

          TextItem(title:"订单编号",value:"${data["unionOrderId"] ?? '--'}",),
          TextItem(title:"服  务  员",value:"${data["waiterName"]==null?'--':(data["waiterName"]==''?'--':data["waiterName"])}",),
          TextItem(title:"评价时间",value:"${data["ctime"] ?? '--' }",),
          TextItem(title:"服务评价",value:"${data["waiterCommentType"]==0?'满意':'不满意'}",),
          TextItem(title:"评价内容",value:"${data["waiterCommentLabel"] ?? '--'}",),
          LineBox(),
          TextItem(title:"菜品评分",value:Row(
              children: <Widget>[
                StartShow(startFraction:data["score"] ?? 0,),
                Text(" ${data["score"] ?? 0}分",
                  style:TextStyleConstant().normal_1_26,
                ),

              ],
          ),
          ),

          InkWell(
            onTap:(){
////v1
//              String v='';
//              showAlert(
//                  context,
//                  content: LongTextFormField(
//                    maxLength: 200,
//                    maxLines: 4,
//                    hintText: '请输入回复内容',
//                    onChanged: (value) {
//                      v=value;
//                    },),
//                  onConfirm:(){
//                    if(v.trim()==''){
//                      toast("回复内容不能为空!");
//                      return;
//                    }
//                    replyContent(provider?.commentListArr[index],v,index);
////                    onConfirm(provider?.commentListArr[index],v,index);
//                  }
//              );

////v2

              provider?.replyClickIndex=index;

              provider?.notifyListeners();

            },
            child: Column(
              children: <Widget>[
                TextItem(title:"订单评价",value:Column(
                  mainAxisAlignment:MainAxisAlignment.start,
                  crossAxisAlignment:CrossAxisAlignment.start,
                  children: <Widget>[
                    Text("${data["content"]}",
                      style: TextStyleConstant().normal_1_26,
                    ),
                    SizedBox(
                      height:6.w,
                    ),
                    (data["photoReviews"]==null || data["photoReviews"]=='')?Container():Container(
                      width:double.infinity,
                      height:300.w,
                      child:ListView.builder(
                        scrollDirection: Axis.horizontal,
                        itemBuilder:(context,index){
                          var imgArr=data["photoReviews"].split("|");
                          return  Container(
                            padding:EdgeInsets.only(
                              right:8.w,
                            ),
                            child: BaseImage(
                              '${imgArr[index] ?? ''}',
//                    width: 260.w,
                              height:300.w,

                            ),
                          );
                        },
                        itemCount:data["photoReviews"].split("|").length,
                      ),
                    ),
                  ],
                ),),
                Selector(
                  builder:(BuildContext context,getCommentListArr, Widget child){
                    return  Container(
                        child:Column(
                          children: <Widget>[

                            Column(
                              children:(provider?.foldStatusArr[index]?getCommentListArr[index]["commentReplyDOList"]:commentFold).map<Widget>((val)=>Container(
                                child:TextItem(

                                  title:"店家回复",
                                  value:"${val["reply"] ?? '--'}",
                                ),

                              )).toList(),
                            ),
                          ],
                        )
                    );


                  },
                  selector:(BuildContext context, StoreCommentProvider storeCommentProvider){
                    return [...storeCommentProvider.getCommentListArr];
                  },
                ),
              ],
            ),
          ),


          (data["commentReplyDOList"]==null || data["commentReplyDOList"].length==0)?Container():GestureDetector(
            onTap:(){
              provider?.foldStatusArr[index]=!provider?.foldStatusArr[index];
              provider?.notifyListeners();
            },
            child: Padding(
              padding:EdgeInsets.only(
                top:6.w,
                bottom:6.w,
              ),
              child: Row(
                children: <Widget>[
                      Padding(
                        padding:EdgeInsets.only(
                          left:46.w,
                          right:16.w,
                        ),
                        child: BaseImage(
                          'assets/image/${!provider?.foldStatusArr[index]?'store_down':'store_up'}.png',
                          width: 26.w,
                          height:26.w,

                        ),
                      ),
                    Text("${!provider?.foldStatusArr[index]?'展开更多回复             ':'收起                  '}",
                      style: TextStyleConstant().normal_2_26,
                    ),




                ],
              ),
            ),
          ),



        ],
      ),
    );
  }
}


class TextItem extends StatelessWidget {
  String title;
  dynamic value;

  TextItem({Key key,this.title,this.value}):super(key:key);
  @override
  Widget build(BuildContext context) {
    return Padding(
      padding:EdgeInsets.only(
        top:10.w,
        bottom:10.w,
      ),
      child: Row(
        mainAxisAlignment:MainAxisAlignment.start,
        crossAxisAlignment:CrossAxisAlignment.start,
        children: <Widget>[
          Text("$title：",
            style: TextStyleConstant().normal_2_26,
          ),
          Expanded(
            child:value is Widget?value:Text("$value",
              style: TextStyleConstant().normal_1_26,
            ),
          )

        ],
      ),
    );
  }
}



//横杠
class LineBox extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height:1.w,
      color:Color.fromRGBO(211, 211, 211, 1),
    );
  }
}


